package com.test.qnews.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.test.qnews.R;
import com.test.qnews.beans.NetDataBean;
import java.util.List;

/**
 * Created by dllo on 16/1/22.
 */
public class JokeAdapter extends BaseAdapter {
    private Context context;
    private List<NetDataBean> datas;

    public JokeAdapter(Context context, List<NetDataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.size() > 0 && datas != null ? datas.size() : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        myViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_joke,null);
            holder = new myViewHolder();

            holder.tv_time = (TextView) convertView.findViewById(R.id.item_joke_time);
            holder.tv_title = (TextView) convertView.findViewById(R.id.item_joke_title);

            convertView.setTag(holder);
        } else {
            holder = (myViewHolder) convertView.getTag();
        }
//        holder.tv_time.setText(datas.get(position).getTime());
        holder.tv_title.setText(datas.get(position).getTitle());
        return convertView;
    }

    public class myViewHolder {
        private TextView tv_title, tv_time;
    }
}

